﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.Serialization;

namespace Code.UI
{
    public class UIPlayer:MonoBehaviour
    {

        public CharacterConfig Config;

        public List<SkillData> SkillList = new List<SkillData>();

        [NonSerialized,OdinSerialize]
        public Dictionary<Skill,int> SkillConfigDict = new Dictionary<Skill,int>();
        public void UseSkill(SkillData data)
        {
            if (CanUseSkill(data)) 
            {
                StartCoroutine(CoolTimeCoro(data));
            }
        }

        public bool CanUseSkill(SkillData data)
        {
            return true&&data.cooldowning;
        }

        private IEnumerator CoolTimeCoro(SkillData data)
        {
            float timer = 0;
            data.cooldowning = false;
            while (true)
            {
                timer+= Time.deltaTime;
                if (data.Config.CoolDownTime - timer <= 0) 
                {
                    data.cooldowning = true;
                    Debug.Log("冷却完成");
                    break;
                }
                yield return null;
            }
        }

        internal void UseCard(Card card)
        {
            if (!CanUseCard()) { return; }
            Debug.Log("玩家使用了："+card.Name);
        }

        private bool CanUseCard()
        {
            return true;
        }
    }
}
